<?php


namespace app\index\controller;
use app\index\model\Article as ArticleModel;
use app\index\model\ArticleClass;
use think\Controller;

class Article extends  Controller
{

    /*获取文章*/
    public function article( )
    {
        $res = new ArticleModel();
        $data = $this->request->param();
        $d=$res->where($data['field'],$data['op'],$data['value'])
            ->field("a_id,title,img,author_name,cTime,ac_id,read_count")
            ->page($data['page'])
            ->limit(10)
            ->select();
        return $d;
    }
    /*获取文章*/
    public function articleOne( )
    {
        $res = new ArticleModel();
        $data = $this->request->param();
        $d=$res->where($data['field'],$data['op'],$data['value'])->find();
        return $d;
    }

    /*添加文章*/
    public function addArticle()
    {
        $res = new ArticleModel();
        $data = $this->request->param();
        return $res->saveModel($data);
    }
    /*更新阅读次数*/
    public function addCount()
    {
        $res = new ArticleModel();
        $data = $this->request->param();
        $res->where('a_id',$data['a_id'])->setInc('read_count');
    }
    public function delete(){
        $data = $this->request->param();
        $res = new ArticleModel();
        return $res->deleteModel($data);
    }
    public function update()
    {
        $res = new ArticleModel();
        $data = $this->request->param();
        return $res->updateModel($data);

    }

    /**
     * 获取文章分类
     */
    public function getAcClass()
    {
        $res = new ArticleClass();
        $data = $this->request->param();
        return $res->selectModel($data);
    }
    /**
     * 新增分类
     */
    public function addAcClass()
    {
        $res = new ArticleClass();
        $data = $this->request->param();
        return $res->saveModel($data);
    }
    public function delAcClass()
    {
        $res = new ArticleClass();
        $data = $this->request->param();
        return $res->deleteModel($data);
    }
    public function countInc(){
        $res = new ArticleModel();
        $data = $this->request->param();
        $res->where([$data['field']=>$data['value']])->setInc($data['field1']);
    }
    public function num(){
        $data = $this->request->param();
        $res =new ArticleModel();
        return $res->where($data['field'],$data['op'],$data['value'])->count();
    }
}